package com.dycloud.project.controller;


import com.dycloud.project.aspectj.lang.annotation.Log;
import com.dycloud.project.aspectj.lang.enums.BusinessType;
import com.dycloud.project.domain.Meetings;
import com.dycloud.project.enums.ServiceTypeEnum;
import com.dycloud.project.request.ReviewMeetingRequest;
import com.dycloud.project.service.IMeetingsService;
import com.dycloud.project.web.controller.BaseController;
import com.dycloud.project.web.domain.AjaxResult;
import com.dycloud.project.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author : renhang
 * @description MeetingsController
 * @date : 2025-07-03 14:04
 **/
@RestController
@RequestMapping("/business/meetings")
public class MeetingsController extends BaseController {
    @Autowired
    private IMeetingsService meetingsService;

    /**
     * 查询会议列表
     */
    @PreAuthorize("@ss.hasPermi('business:meetings:list')")
    @GetMapping("/list")
    public TableDataInfo list(Meetings meetings) {
        startPage();
        return meetingsService.selectMeetingsList(meetings, ServiceTypeEnum.WEB.getCode());
    }


    /**
     * 获取会议详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:meetings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(meetingsService.selectMeetingsById(id));
    }

    /**
     * 新增会议
     */
    @PreAuthorize("@ss.hasPermi('business:meetings:add')")
    @Log(title = "会议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Meetings meetings) {
        return toAjax(meetingsService.insertMeetings(meetings));
    }

    /**
     * 修改会议
     */
    @PreAuthorize("@ss.hasPermi('business:meetings:edit')")
    @Log(title = "会议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Meetings meetings) {
        return toAjax(meetingsService.updateMeetings(meetings));
    }

    /**
     * 删除会议
     */
    @PreAuthorize("@ss.hasPermi('business:meetings:remove')")
    @Log(title = "会议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(meetingsService.deleteMeetingsByIds(ids));
    }


    /**
     * 管理员审核
     *
     * @param request request
     * @return
     */
    @PreAuthorize("@ss.hasRole('admin')")
    @Log(title = "会议审核", businessType = BusinessType.REVIEW)
    @PutMapping("review")
    public AjaxResult review(@RequestBody @Validated ReviewMeetingRequest request) {
        meetingsService.review(request);
        return AjaxResult.success();
    }
}